package thread.fenjiesuoyufenduansuo;


import java.util.HashSet;
import java.util.Set;

public  class DecomposeClazz{
    private final Set<String> allUsers = new HashSet<String>();
    private final Set<String> allComputers = new HashSet<String>();

    public synchronized void addUser(String user){ //公用一把锁
        try {
            Thread.currentThread().sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("添加一个用户成功:"+user);
        allUsers.add(user);
    }

    public synchronized void addComputer(String computer){
        try {
            Thread.currentThread().sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("添加电脑:"+computer+"成功");
        allComputers.add(computer);
    }
}
